<?php
/*
** Controller: Bangdiem
** File: bangdiem.php
** Author: ManhVT
** Website: http://vosvn.com.vn
** Email: manhvt89@gmail.com
** Version: 2.0.1
**
*/
?>
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Bangdiem extends MY_Controller {

	public $data 	= 	array();
 	public $_template = array();
	public function __construct() {
		//parent::Controller();
		parent::__construct(); //for CI 2.x users 
		$this->load->module_model('member', 'bangdiem_model', 'bangdiem');
		$this->load->module_model('member', 'qlsv_model', 'hocvien');
		$this->load->library('basic_library');
		$this->load->helper('text');
		$this->user = $this->access->get_user();
		$this->load->helper('url');
		$this->access->restrict();
	}
	
	public function lockmh($id = null, $idlop)
	{
		if ($id == null)
		{
			$id = $this->input->post('id');
		}
			
		$this->bangdiem->lockmh($id,1, $idlop);
		redirect('member/bangdiem/nhap_diem/'.$idlop, 'refresh');
	}
	/*
	 * Nhap diem tu lop
	 */
	public function nhap_diem($lopid)
	{
		$data['ItemID'] = 'User';
		$data['title'] = 'Nhập điểm môn học';
		$data['description'] = 'Nhập điểm môn học';
		$this->load->helper('form');
		$userid = $this->user->id;
		$lang_working = load_language_working();
		$data['monhocOftheClass'] = $this->hocvien->get_monhoc_of_class_by_id($lopid);
		$data['infoOfClass'] = $this->hocvien->get_lop_info($lopid);
		//var_dump($data['monhocOftheClass']);
		//here is validation form
		$data['idlop'] = $lopid;
		$this->_template['page']	= 'users/bangdiem/add_diem';
		$this->system_library->load($this->_template['page'], $data);
	}
	public function list_class()
	{
		$data['ItemID'] = 'User';
		$data['title'] = 'Danh sách Lớp';
		$data['description'] = 'Danh sách lớp';
		$this->load->library('pagination');
		
		$config = array();
		$config['base_url'] = base_url().'member/bangdiem/list_class';
		$config['total_rows'] = $this->bangdiem->count_all_lop();
		$config['per_page'] = 100;
		$config['uri_segment'] = 4;
		$config['num_links'] = 5;
		$config['first_link'] = 'First';
		$config['last_link'] = 'Last';
		$config['next_link'] = 'Next';
		$config['prev_link'] = 'Prev';
		$this->pagination->initialize($config);
		$page = ($this->uri->segment(4))? $this->uri->segment(4):0;
		$data['sotrang']	=	$this->uri->segment(4);
		
		$data['classes']	=	$this->bangdiem->get_all_class($config['per_page'], $page);
		$data['links'] = $this->pagination->create_links();
		$this->_template['page']	= 'users/bangdiem/list_class';
		$this->system_library->load($this->_template['page'], $data);
	}
	
	public function index()
	{
		//$this->access->restrict('Member.Monhoc.Index');
		$data['ItemID'] = 'User';
		$data['title'] = 'Danh sách Bảng điểm';
		$data['description'] = 'Quản lý danh sách Điểm';
		$this->access->restrict();
		$this->_template['page']	= 'users/bangdiem/home_bangdiem';
		$this->system_library->load($this->_template['page'], $data);
	}
	
	
	// Hien thi lua chon mon hoc de nhap diem
	public function add_diem()
	{
		//$this->access->restrict('Member.Monhoc.Edit');
		$data['ItemID'] = 'User';
		$data['title'] = 'Nhập điểm môn học';
		$data['description'] = 'Nhập điểm môn học';
		$this->load->helper('form');
		$userid = $this->user->id;
		$lang_working = load_language_working();
		
		//here is validation form
		$this->form_validation->set_rules('year', 'Năm bắt đầu', 'required');
		$this->form_validation->set_rules('lophoc','Lớp học','required');
		$this->form_validation->set_rules('monhoc','Môn học','required');
		$this->form_validation->set_rules('loaidiem','Loại điểm','required');
		
		$this->form_validation->set_error_delimiters('', '<br />');
		$idlist = $this->input->post('listIds');
		$results = explode(",", $idlist);
		
		if ($this->form_validation->run() == TRUE)
		{
			$this->bangdiem->add_diem($results);
			$this->session->set_flashdata('message', 'Thêm mới thành công');
			redirect('member/bangdiem/', 'refresh');
		}
		$this->_template['page']	= 'users/bangdiem/add_diem';
		$this->system_library->load($this->_template['page'], $data);
	}
	
	function add_chitietdiem($mon_id, $lop_id)
	{
		$data['ItemID'] = 'User';
		$data['title'] = 'Nhập điểm môn học';
		$data['description'] = 'Nhập điểm môn học';
		
		//$data['solanktra'] = $id;
		$data['idmon'] = $mon_id;
		$data['idlop'] = $lop_id;
		//$data['type'] = $type;
		
		$data['students'] = $this->bangdiem->get_students_by_class($lop_id);
		$this->form_validation->set_rules('listIds','Loại điểm','');
		
		$this->form_validation->set_error_delimiters('', '<br />');
		$idlist = $this->input->post('listIds');
		$results = explode(",", $idlist);
		
		if ($this->form_validation->run() == TRUE)
		{
			$this->bangdiem->add_chitietdiem($mon_id,$lop_id,$results);
			$this->session->set_flashdata('message', 'Thêm mới thành công');
			redirect('member/bangdiem/nhap_diem/'.$lop_id, 'refresh');
		}
		$this->_template['page']	= 'users/bangdiem/add_chitietdiem';
		$this->system_library->load($this->_template['page'], $data);
	}
	
	function edit_chitietdiem($mon_id, $lop_id)
	{
		$data['ItemID'] = 'User';
		$data['title'] = 'Nhập điểm môn học';
		$data['description'] = 'Nhập điểm môn học';
	
		//$data['solanktra'] = $id;
		$data['idmon'] = $mon_id;
		$data['idlop'] = $lop_id;
		//$data['type'] = $type;
		
		$data['students'] = $this->bangdiem->get_tableOfMarkbyTheClassTheSubject($mon_id, $lop_id);
		$this->form_validation->set_rules('listIds','Loại điểm','');
	
		$this->form_validation->set_error_delimiters('', '<br />');
		$idlist = $this->input->post('listIds');
		$results = explode(",", $idlist);
	
		if ($this->form_validation->run() == TRUE)
		{
			$this->bangdiem->edit_chitietdiem($results, $mon_id, $lop_id);
			$this->session->set_flashdata('message', 'Thêm mới thành công');
			redirect('member/bangdiem/nhap_diem/'.$lop_id, 'refresh');
		}
		$this->_template['page']	= 'users/bangdiem/edit_chitietdiem';
		$this->system_library->load($this->_template['page'], $data);
	}
	
	function exportexcel_bangdiem($idlop=null)
	{
		//echo $this->input->post('idlop'); echo $idlop;
		$idlop = $this->input->post('idlop');
		$arrT = array();
		$arrT[1] = 'A';
		$arrT[2] = 'B';
		$arrT[3] = 'C';
		$arrT[4] = 'D';
		$arrT[5] = 'E';
		$arrT[6] = 'F';
		$arrT[7] = 'G';
		$arrT[8] = 'H';
		$arrT[9] = 'I';
		$arrT[10] = 'J';
		$arrT[11] = 'K';
		$arrT[12] = 'L';
		$arrT[13] = 'M';
		$arrT[14] = 'N';
		$arrT[15] = 'O';
		$arrT[16] = 'P';
		$arrT[17] = 'Q';
		$arrT[18] = 'R';
		$arrT[19] = 'S';
		$arrT[20] = 'T';
		$arrT[21] = 'U';
		$arrT[22] = 'V';
		$arrT[23] = 'W';
		$arrT[24] = 'X';
		$arrT[25] = 'Y';
		$arrT[26] = 'Z';
		$arrT[27] = 'AA';
		$arrT[28] = 'AB';
		$arrT[29] = 'AC';
		$arrT[30] = 'AD';
		$arrT[31] = 'AE';
		$arrT[32] = 'AF';
		$arrT[33] = 'AG';
		$arrT[34] = 'AH';
		$arrT[35] = 'AI';
		$arrT[36] = 'AJ';
		$arrT[37] = 'AK';
		$arrT[38] = 'AL';
		$arrT[39] = 'AM';
		$arrT[40] = 'AN';
		$arrT[41] = 'AO';
		$arrT[42] = 'AP';
		$arrT[43] = 'AQ';
		$arrT[44] = 'AR';
		$arrT[45] = 'AS';
		$arrT[46] = 'AT';
		$arrT[47] = 'AU';
		$arrT[48] = 'AV';
		$arrT[49] = 'AW';
		$arrT[50] = 'AX';
		$arrT[51] = 'AY';
		$data['hocviens'] = $this->bangdiem->get_student_by_class($idlop);
		$data['subjects']	=	$this->bangdiem->get_subject_by_class($idlop,200,1);
		$data['exams']	=	$this->bangdiem->get_subject_by_class($idlop,200,2);
		//var_dump(count($data['exams']));
		$data['count'] = $this->bangdiem->count_all_subject_by_class($idlop);
		
		
		$data['lopinfo']	=	$this->bangdiem->get_lop_info($idlop);
	
		$type = $this->bangdiem->get_clType($idlop);	
		//load our new PHPExcel library
		$this->load->library('exzel');
		//activate worksheet number 1
		$this->exzel->setActiveSheetIndex(0);
		//name the worksheet
		$this->exzel->getActiveSheet()->setTitle('Bang Diem');
		//set cell A1 content with some text
		if($type == 1)
		{
			$this->exzel->getActiveSheet()->getColumnDimension('A')->setWidth(5);
			$this->exzel->getActiveSheet()->setCellValue('A7', 'TT');
			$this->exzel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
			$this->exzel->getActiveSheet()->setCellValue('B7', 'Họ và tên');
			$this->exzel->getActiveSheet()->getColumnDimension('C')->setWidth(15);
			$this->exzel->getActiveSheet()->setCellValue('C7', 'Ngày sinh');
			$this->exzel->getActiveSheet()->setCellValue('D7', 'Nơi sinh');
			$this->exzel->getActiveSheet()->setCellValue('E7', 'Module môn học');
			//change the font size
			$this->exzel->getActiveSheet()->getStyle('A7')->getFont()->setSize(14);
			$this->exzel->getActiveSheet()->getStyle('E7')->getFont()->setSize(18);
			//make the font become bold
			$this->exzel->getActiveSheet()->getStyle('A7')->getFont()->setBold(false);
			//merge cell A1 until D1
			$this->exzel->getActiveSheet()->mergeCells('A7:A9');
			//set aligment to center for that merged cell (A1 to D1)
			$this->exzel->getActiveSheet()->getStyle('A7')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
			$this->exzel->getActiveSheet()->getStyle('E7')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); //setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
			$this->exzel->getActiveSheet()->mergeCells('B7:B9');
			$this->exzel->getActiveSheet()->mergeCells('C7:C9');
			$this->exzel->getActiveSheet()->mergeCells('D7:D9');
		
			$idex = 4;
			$jdex = 5;
			foreach($data['subjects'] as $subject)
			{
				$idex++;
			}
			$mergeCell =  'E7:'.$arrT[$idex].'7';
			$this->exzel->getActiveSheet()->mergeCells($mergeCell);
			foreach($data['subjects'] as $subject)
			{
				$colname = $arrT[$jdex].'8';
				//echo $colname; exit();
				$this->exzel->getActiveSheet()->getStyle($arrT[$jdex].'8')->getAlignment()->setTextRotation(90);
				$this->exzel->getActiveSheet()->getColumnDimension($arrT[$jdex])->setWidth(5);
				$this->exzel->getActiveSheet()->setCellValue($arrT[$jdex].'8', $subject['mamon']);
				$colname = $arrT[$jdex].'9';
				//echo $colname; exit();
				$this->exzel->getActiveSheet()->setCellValue($arrT[$jdex].'9', $subject['heso']);
				$jdex++;
			}
			//NEXT COLUM		
			$jdex = $idex + 1;
			//var_dump($data['exams']); exit();
			foreach ($data['exams'] as $exam)
			{
				
				$mergeCell = $arrT[$jdex].'7'.':'.$arrT[$jdex].'9';
				$this->exzel->getActiveSheet()->mergeCells($mergeCell);
				//echo $colname; exit();
				$this->exzel->getActiveSheet()->getStyle($arrT[$jdex].'7')->getAlignment()->setTextRotation(90);
				$this->exzel->getActiveSheet()->getColumnDimension($arrT[$jdex])->setWidth(5);
				$this->exzel->getActiveSheet()->setCellValue($arrT[$jdex].'7', $exam['mamon']);
				$jdex++;
				
			}
			$idex = $jdex;
			$mergeCell = $arrT[$idex].'7'.':'.$arrT[$idex].'9';
			$this->exzel->getActiveSheet()->mergeCells($mergeCell);
			$this->exzel->getActiveSheet()->getStyle($arrT[$idex].'7')->getAlignment()->setTextRotation(90);
			$this->exzel->getActiveSheet()->getColumnDimension($arrT[$idex])->setWidth(5);
			$this->exzel->getActiveSheet()->setCellValue($arrT[$idex].'7', 'ĐTK');
			
			$idex++;
			$mergeCell = $arrT[$idex].'7'.':'.$arrT[$idex].'9';
			$this->exzel->getActiveSheet()->mergeCells($mergeCell);
			$this->exzel->getActiveSheet()->getStyle($arrT[$idex].'7')->getAlignment()->setTextRotation(90);
			$this->exzel->getActiveSheet()->getColumnDimension($arrT[$idex])->setWidth(5);
			$this->exzel->getActiveSheet()->setCellValue($arrT[$idex].'7', 'XẾP LOẠI');
		
			// INSERT DIEM
			$stt = 1;
			$irow = 10;
			
			foreach($data['hocviens'] as $hocvien)
			{
				//var_dump($hocvien['kind']);
				if($hocvien['kind'] > 0)
				{
					
				}else
				{
					$this->exzel->getActiveSheet()->setCellValue('A'.$irow, $stt);
					$this->exzel->getActiveSheet()->setCellValue('B'.$irow, $hocvien['tenhv']);
					$this->exzel->getActiveSheet()->setCellValue('C'.$irow, date('d/m/Y',strtotime($hocvien['ngaysinh'])));
					$this->exzel->getActiveSheet()->setCellValue('D'.$irow, $hocvien['thuongtru']);
					$jdex = 5;
					foreach($data['subjects'] as $subject)
					{
						$point = $this->basic_library->get_total_mark_of_students_by_class($hocvien['id'],$subject['id']);
						if($point)
						{
							$mark = $point->diemtrungbinh;
						}
						else {
							$mark = "Chưa nhập điểm";
						}
						$this->exzel->getActiveSheet()->setCellValue($arrT[$jdex].$irow, $mark);
						$jdex++;
					}
					foreach ($data['exams'] as $exam)
					{
						//echo $colname; exit();
						$point = $this->basic_library->get_total_mark_of_students_by_class($hocvien['id'],$exam['id']);
						if($point)
						{
						$mark = $point->diemtrungbinh;
						}
						else {
							$mark = "Chưa nhập điểm";
						}
						$this->exzel->getActiveSheet()->setCellValue($arrT[$jdex].$irow, $mark);
						$jdex++;
							
					}
					$dtk = round($hocvien['dtk'],1);
					$this->exzel->getActiveSheet()->setCellValue($arrT[$jdex].$irow, $dtk);
					$jdex++;
					$xl = $hocvien['xeploai'];
					$this->exzel->getActiveSheet()->setCellValue($arrT[$jdex].$irow, $xl);
					$irow++;
					$stt++;
				}
			}
		}
		else
		{
			$this->exzel->getActiveSheet()->getColumnDimension('A')->setWidth(5);
			$this->exzel->getActiveSheet()->setCellValue('A7', 'TT');
			$this->exzel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
			$this->exzel->getActiveSheet()->setCellValue('B7', 'Họ và tên');
			$this->exzel->getActiveSheet()->getColumnDimension('C')->setWidth(15);
			$this->exzel->getActiveSheet()->setCellValue('C7', 'Ngày sinh');
			$this->exzel->getActiveSheet()->setCellValue('D7', 'Nơi sinh');
			$this->exzel->getActiveSheet()->setCellValue('E7', 'Module môn học');
			//change the font size
			$this->exzel->getActiveSheet()->getStyle('A7')->getFont()->setSize(14);
			$this->exzel->getActiveSheet()->getStyle('E7')->getFont()->setSize(18);
			//make the font become bold
			$this->exzel->getActiveSheet()->getStyle('A7')->getFont()->setBold(false);
			//merge cell A1 until D1
			$this->exzel->getActiveSheet()->mergeCells('A7:A9');
			//set aligment to center for that merged cell (A1 to D1)
			$this->exzel->getActiveSheet()->getStyle('A7')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
			$this->exzel->getActiveSheet()->getStyle('E7')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); //setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
			$this->exzel->getActiveSheet()->mergeCells('B7:B9');
			$this->exzel->getActiveSheet()->mergeCells('C7:C9');
			$this->exzel->getActiveSheet()->mergeCells('D7:D9');
		
			$idex = 4;
			$jdex = 5;
			foreach($data['subjects'] as $subject)
			{
				$idex++;
			}
			$mergeCell =  'E7:'.$arrT[$idex].'7';
			$this->exzel->getActiveSheet()->mergeCells($mergeCell);
			foreach($data['subjects'] as $subject)
			{
				$colname = $arrT[$jdex].'8';
				//echo $colname; exit();
				$this->exzel->getActiveSheet()->getStyle($arrT[$jdex].'8')->getAlignment()->setTextRotation(90);
				$this->exzel->getActiveSheet()->getColumnDimension($arrT[$jdex])->setWidth(5);
				$this->exzel->getActiveSheet()->setCellValue($arrT[$jdex].'8', $subject['mamon']);
				$colname = $arrT[$jdex].'9';
				//echo $colname; exit();
				$this->exzel->getActiveSheet()->setCellValue($arrT[$jdex].'9', $subject['heso']);
				$jdex++;
			}
			//NEXT COLUM
			$idex++;
			$mergeCell = $arrT[$idex].'7'.':'.$arrT[$idex].'9';
			$this->exzel->getActiveSheet()->mergeCells($mergeCell);
			
			$this->exzel->getActiveSheet()->getStyle($arrT[$idex].'7')->getAlignment()->setTextRotation(90);
			$this->exzel->getActiveSheet()->getColumnDimension($arrT[$idex])->setWidth(5);
			$this->exzel->getActiveSheet()->setCellValue($arrT[$idex].'7', 'ĐTB');
			$jdex = $idex + 1;
			//var_dump($data['exams']); exit();
			foreach ($data['exams'] as $exam)
			{
				
				$mergeCell = $arrT[$jdex].'7'.':'.$arrT[$jdex].'9';
				$this->exzel->getActiveSheet()->mergeCells($mergeCell);
				//echo $colname; exit();
				$this->exzel->getActiveSheet()->getStyle($arrT[$jdex].'7')->getAlignment()->setTextRotation(90);
				$this->exzel->getActiveSheet()->getColumnDimension($arrT[$jdex])->setWidth(5);
				$this->exzel->getActiveSheet()->setCellValue($arrT[$jdex].'7', $exam['mamon']);
				$jdex++;
				
			}
			$idex = $jdex;
			//echo $idex;
			$mergeCell = $arrT[$idex].'7'.':'.$arrT[$idex].'9';
			$this->exzel->getActiveSheet()->mergeCells($mergeCell);
			$this->exzel->getActiveSheet()->getStyle($arrT[$idex].'7')->getAlignment()->setTextRotation(90);
			$this->exzel->getActiveSheet()->getColumnDimension($arrT[$idex])->setWidth(5);
			$this->exzel->getActiveSheet()->setCellValue($arrT[$idex].'7', 'ĐTK');
			
			$idex++;
			$mergeCell = $arrT[$idex].'7'.':'.$arrT[$idex].'9';
			$this->exzel->getActiveSheet()->mergeCells($mergeCell);
			$this->exzel->getActiveSheet()->getStyle($arrT[$idex].'7')->getAlignment()->setTextRotation(90);
			$this->exzel->getActiveSheet()->getColumnDimension($arrT[$idex])->setWidth(5);
			$this->exzel->getActiveSheet()->setCellValue($arrT[$idex].'7', 'XẾP LOẠI');
		
			// INSERT DIEM
			$stt = 1;
			$irow = 10;
			
			foreach($data['hocviens'] as $hocvien)
			{
				
				if($hocvien['kind'] > 0)
				{
					
				}else
				{
					$this->exzel->getActiveSheet()->setCellValue('A'.$irow, $stt);
					$this->exzel->getActiveSheet()->setCellValue('B'.$irow, $hocvien['tenhv']);
					$this->exzel->getActiveSheet()->setCellValue('C'.$irow, date('d/m/Y',strtotime($hocvien['ngaysinh'])));
					$this->exzel->getActiveSheet()->setCellValue('D'.$irow, $hocvien['thuongtru']);
					$jdex = 5;
					foreach($data['subjects'] as $subject)
					{
						$point = $this->basic_library->get_total_mark_of_students_by_class($hocvien['id'],$subject['id']);
						if($point)
						{
							$mark = $point->diemtrungbinh;
						}
						else {
							$mark = "Chưa nhập điểm";
						}
						$this->exzel->getActiveSheet()->setCellValue($arrT[$jdex].$irow, $mark);
						$jdex++;
					}
					$dtb = round($hocvien['dtb'],1);
					$this->exzel->getActiveSheet()->setCellValue($arrT[$jdex].$irow, $dtb);
					
					$jdex++;
					foreach ($data['exams'] as $exam)
					{
						//echo $colname; exit();
						$point = $this->basic_library->get_total_mark_of_students_by_class($hocvien['id'],$exam['id']);
						if($point)
						{
						$mark = $point->diemtrungbinh;
						}
						else {
							$mark = "Chưa nhập điểm";
						}
						$this->exzel->getActiveSheet()->setCellValue($arrT[$jdex].$irow, $mark);
						$jdex++;
							
					}
					$dtk = round($hocvien['dtk'],1);
					$this->exzel->getActiveSheet()->setCellValue($arrT[$jdex].$irow, $dtk);
					$jdex++;
					$xl = $hocvien['xeploai'];
					$this->exzel->getActiveSheet()->setCellValue($arrT[$jdex].$irow, $xl);
					//$jdex++;
					//$this->exzel->getActiveSheet()->setCellValue($arrT[$jdex].$irow, $hocvien['kind']);
					$irow++;
					$stt++;
				}
			}
		
		}
		$filename='bang_diem_lop_'.$idlop.'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
		 
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->exzel, 'Excel5');
		//force user to download the Excel file without writing it to server's HD
		//$objWriter->save("nameoffile.xls");
		$objWriter->save('php://output');
		exit();
		////////////////////

	}
	
	/*
	 * Xem bảng điểm cả lớp
	 */
	
	function view_bangdiem($idlop = NULL)
	{
		$data['ItemID'] = 'User';
		$data['title'] = 'Xem bảng tổng kết điểm theo lớp';
		$data['description'] = 'Xem bảng tổng kết điểm theo lớp';
		$data['idlop'] = $idlop;
		//$data['type'] = $this->bangdiem->get_clType($idlop);
		$data['lopinfo']	=	$this->bangdiem->get_lop_info($idlop);
		$data['hocviens'] = $this->bangdiem->get_student_by_class($idlop);
		$data['subjects']	=	$this->bangdiem->get_subject_by_class($idlop,200,1);
		$data['exams']	=	$this->bangdiem->get_subject_by_class($idlop,200,2);
		//var_dump(count($data['exams']));
		$data['count'] = $this->bangdiem->count_all_subject_by_class($idlop);
		$data['type'] = $data['lopinfo']->type;
		$type = $data['lopinfo']->type;
		if($type==1)
		{
			$this->load->view('templates/default/layout/pages/users/bangdiem/view_bangdiem_scn', $data);
			//echo json_encode($data['hocviens']);
		}else{
			$this->load->view('templates/default/layout/pages/users/bangdiem/view_bangdiem', $data);
		}
		//$this->_template['page']	= 'users/bangdiem/view_bangdiem';
		//$this->system_library->load($this->_template['page'], $data);
	}
	
	function view_bangdiem_canhan($hv_id,$lop_id)
	{
		
	}
	
	public function get_hocvien($id)
	{
		//$this->bangdiem->ajaxget_hocvien($id);
		header('Content-Type: application/x-json; charset=utf-8');
		echo(json_encode($this->bangdiem->ajaxget_hocvien($id)));
	
	}
	/*
	 * Lấy danh sách định mức của môn
	*/
	public function get_loaidiem($id_mon,$id_lop)
	{
		//var_dump($this->bangdiem->ajaxget_loaidiem($id_mon));
		header('Content-Type: application/x-json; charset=utf-8');
		echo(json_encode($this->bangdiem->ajaxget_loaidiem($id_mon,$id_lop)));
	
	}
	/*
	 * Lấy danh sách lớp theo năm bắt đầu
	*/
	public function get_lophoc_byYear($year)
	{
		header('Content-Type: application/x-json; charset=utf-8');
		echo(json_encode($this->bangdiem->ajaxget_lop_byYear($year)));
		//$this->qlsv->get_lop_byYear($year);
	}
	
	/*
	 * Lấy danh sách môn học theo lớp (id_lop) get_monhoc_bylop
	 * Ajax
	*/
	public function get_monhoc_bylop($id_lop)
	{
		header('Content-Type: application/x-json; charset=utf-8');
		echo(json_encode($this->bangdiem->ajaxget_monhoc_bylop($id_lop)));
		//$this->qlsv->get_lop_byYear($year);
	}
}

/* Location: ./application/modules/member/controllers/monhoc.php */